<?php

namespace App\Http\Requests\Admin\Config;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class GameRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        if (request()->method() == 'POST') {
            return [
                'game_id' => 'required|unique:mc_games',
                'game_name' => 'required',
                'model_name' => 'required',
                'status' => 'required:integer',
            ];
        } elseif (request()->method() == 'PATCH') {
            return [
                'game_id' => [
                    'required',
                    Rule::unique('mc_games')
                        ->where('game_id', request()->game_id)
                        ->whereNot('id', request()->route('game')),
                ],
                'game_name' => 'required',
                'model_name' => 'required',
                'status' => 'required:integer',
            ];
        }
    }

    /**
     * 提示信息s
     * @return array
     */
    public function messages()
    {
        return [
            'game_id.required' => '游戏ID不能为空',
            'game_id.unique' => '游戏ID不能重复',
            'game_name.required' => '游戏名称不能为空',
            'model_name.required' => '游戏类名不能为空',
            'status.required' => '状态不能为空',
            'status.integer' => '状态必须是数字',
        ];
    }
}
